#include <iostream>
#include <cstring>
#include <string>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include "Log.hpp"
using std::cout;
using std::cin;
using std::endl;


int main()
{
    //创建套接字
    int sockfd = socket(AF_INET, SOCK_STREAM,  0);

    //填充服务器信息
    struct sockaddr_in server;
    memset(&server, 0, sizeof(server));
    server.sin_family = AF_INET;
    server.sin_port = htons(8080);
    inet_aton("120.53.91.43", &server.sin_addr);

    //建立连接
    connect(sockfd, (sockaddr*)&server, sizeof(server));

    while(1)
    {
        //发送数据
        std::string message; 
        getline(cin,message);
        write(sockfd, message.c_str(), message.size());

        //接收数据
        char buffer[1024];
        int n = read(sockfd, buffer, sizeof(buffer));
        buffer[n] = 0;
        cout << buffer << endl;
    }


    return 0;
}

